package com.hmc.modules.material.service.tqmtqp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmc.common.service.impl.CrudServiceImpl;
import com.hmc.common.constant.Constant;
import com.hmc.modules.material.dao.tqmtqp.Tqmtqp1Dao;
import com.hmc.modules.material.dto.tqmtqp.Tqmtqp1DTO;
import com.hmc.modules.material.entity.tqmtqp.Tqmtqp1Entity;
import com.hmc.modules.material.service.tqmtqp.Tqmtqp1Service;
import com.hmc.modules.security.user.SecurityUser;
import com.hmc.modules.sjfx.dto.sjfx.GghfKlqdDTO;
import com.hmc.modules.sjfx.dto.sjfx.LashenDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 检化验实绩_拉伸
 *
 * @author hmc wengxiulinluman@qq.com
 * @since 3.0 2023-11-29
 */
@Service
public class Tqmtqp1ServiceImpl extends CrudServiceImpl<Tqmtqp1Dao, Tqmtqp1Entity, Tqmtqp1DTO> implements Tqmtqp1Service {

    @Autowired
    private Tqmtqp1Dao tqmtqp1Dao;

    @Override
    public QueryWrapper<Tqmtqp1Entity> getWrapper(Map<String, Object> params){
        QueryWrapper<Tqmtqp1Entity> wrapper = new QueryWrapper<>();

        String id = (String)params.get("id");
        wrapper.eq(StringUtils.isNotBlank(id), "ID", id);

        return wrapper;
    }

    /**
     * 查询钢管-焊缝的抗拉强度
     * @return
     */
    @Override
    public List<GghfKlqdDTO> queryKlqdGghf() {
        // 查询钢管-焊缝的抗拉强度
        List<GghfKlqdDTO> gghfKlqdDTOList =tqmtqp1Dao.queryKlqdGghf();
        return null;
    }

    /**
     * 查询拉伸测试的结果，将拉伸测试的结果按照sampleLotNo分组
     * @return
     */
    @Override
    public HashMap<String, List<LashenDTO>> queryTqmtqp1BySampleLotNo() {
        HashMap<String, List<LashenDTO>> laShenMap = new HashMap<>();
        List<LashenDTO> list = tqmtqp1Dao.queryTqmtqp1BySampleLotNo();
        for (LashenDTO lashenDTO : list) {
            if(laShenMap.containsKey(lashenDTO.getSampleLotNo())){
                List<LashenDTO> laShenEntityList = laShenMap.get(lashenDTO.getSampleLotNo());
                laShenEntityList.add(lashenDTO);
            }else{
                List<LashenDTO> laShenEntityList = new ArrayList<>();
                laShenEntityList.add(lashenDTO);
                laShenMap.put(lashenDTO.getSampleLotNo(), laShenEntityList);
            }
        }
        return laShenMap;
    }
}